<?php
require_once 'common.php';
require_once 'OaAppConfigOrderModel.php';

class OaOnlineModel extends OpModel
{
    
    public function __construct($logger = null)
    {
        if (is_null($logger)) {
            $logger = getOaModelLogger();
        }
        parent::__construct($logger);
    }
    
    /**
     * 获取基本信息
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('basic_info'));
            if (is_array($snapshot)) {
                return $snapshot['basic_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取区
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppAreasOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('area_info'));
            if (is_array($snapshot)) {
                return $snapshot['area_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取组
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppGroupsOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('group_info'));
            if (is_array($snapshot)) {
                return $snapshot['group_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取游戏服务器
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppServersOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('server_info'));
            if (is_array($snapshot)) {
                return $snapshot['server_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取登录服务器
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppLoginServersOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('login_server_info'));
            if (is_array($snapshot)) {
                return $snapshot['login_server_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取登录服务器生效范围
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppLoginServerValidTosOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('login_server_valid_info'));
            if (is_array($snapshot)) {
                return $snapshot['login_server_valid_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取发货服务器
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppPayServersOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('pay_server_info'));
            if (is_array($snapshot)) {
                return $snapshot['pay_server_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
    
    /**
     * 获取发货服务器生效范围
     * @param int $appId
     * @param int $env
     * @return array|null|boolean
     */
    public function getAppPayServerValidTosOnline($appId, $env = OaAppModel::APP_CONFIG_ENV_PRODUCTION)
    {
        $appConfigOrderModel = new OaAppConfigOrderModel($this->_logger);
        $order = $appConfigOrderModel->getAppLastConfigOrder($appId);
        if (is_array($order)) {
            $snapshot = $appConfigOrderModel->getAppSnapshot($order['id'], $env, array('pay_server_valid_info'));
            if (is_array($snapshot)) {
                return $snapshot['pay_server_valid_info'];
            } else {
                return null;
            }
        } else {
            return null;
        }
    }	  
}
?>